"""
模板代码生成
"""

def doRecord():
    
    # 连接窗口
    # conn()
    
<%  if (typeof actions !== 'undefined') {_%>
    img_dir = TempleteDir('<%=imgdir%>')
<%  let lastRunTime = 0 _%>
<%      for (i in actions) { _%>

<%          let action = actions[i] _%>
<%  let t = action.t _%>
    # time.sleep(<%= (t - lastRunTime) / 1000 %>) 
<%  lastRunTime = t _%>
<%          if(action.remark){ _%>
    # <%=action.remark %>
<%          }_%>
<%          if (action.action_type =='move') { _%>
<%              let p1 = action.ext_data[0]; _%>
<%              let p2 = action.ext_data[action.ext_data.length-1]; _%>
    M.moveTo( <%= p1.x %> , <%= p1.y %>)
    M.moveTo( <%= p2.x %> , <%= p2.y %>)
<%          }_%>
<%          if (action.action_type =='press' && action.device =='mouse') { _%>
<%              let btn = action.key.name _%>
<%              let x = action.point[0] _%>
<%              let y = action.point[1] _%>
    M.<%=btn%>_click((<%=x %>,<%=y %>))
    # M.<%=btn%>_click(img_dir.tpl( '<%=action.ext_data.img%>' ))
<%          }_%>
<%          if (action.action_type =='release' && action.device =='mouse') { _%>
<%              let btn = action.key.name _%>
<%              let x = action.point[0] _%>
<%              let y = action.point[1] _%>

    M.<%=btn%>_release((<%=x %>,<%=y %>))
<%          }_%>
<%          if (action.device =='keyboard') { _%>
<%              let key = action.key.name || action.key.char _%>
    KB.<%= action.action_type %>('<%= key %>') _%>
                
<%          }_%>
_%>
<%      }_%>
<% } _%>    